package demo3;

//牛客网:小葱的01串
//https://ac.nowcoder.com/acm/problem/230830

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String str = in.next();
        int ret = 0;
        int num1 = 0, num0 = 0;
        for(int i = 0; i<n; i++) {
            if(str.charAt(i) == '1') num1++;
            else num0++;
        }
        
        int x1 = 0, x0 = 0;
        for(int i = 0, j = 0; i<n-1; i++) {
            if(str.charAt(i) == '1') x1++;
            else x0++;
            
            if(i-j+1 > n/2) {
                if(str.charAt(j) == '1') x1--;
                else x0--;
                j++;
            }
            
            if(x1 == num1/2 && x0 == num0/2) ret += 2;
        }
        System.out.println(ret);
    }
}